package site.marqstree.kotlin.library.good.ui.fragment.category.centent.recyclerview.provider

import android.app.Activity
import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.entity.node.BaseNode
import com.chad.library.adapter.base.provider.BaseNodeProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import org.jetbrains.anko.startActivity
import site.marqstree.kotlin.library.base.util.GlideUtil
import site.marqstree.kotlin.library.base.util.callback.CallbackManager
import site.marqstree.kotlin.library.base.util.callback.CallbackType
import site.marqstree.kotlin.library.base.util.callback.IGlobalCallback
import site.marqstree.kotlin.library.good.R
import site.marqstree.kotlin.library.good.ui.activity.goodlist.ActivityGoodList
import site.marqstree.kotlin.library.good.ui.fragment.category.centent.bean.BrandBean
import javax.inject.Inject


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.good.ui.fragment.category.centent.recyclerview
 * 文件名: SecondNodeProvider
 * 创建者: marqstree
 * 创建时间: 2020/3/7 15:26
 * 描述: 商品明细
 */
class SecondNodeProvider: BaseNodeProvider() {

    init{
        addChildClickViewIds(R.id.iv)
    }

    override val itemViewType: Int
        get() = 1
    override val layoutId: Int
        get() = R.layout.category_content_section_content

    override fun convert(helper: BaseViewHolder, data: BaseNode) {
        val entity: BrandBean = data as BrandBean

        val iv = helper.getView<ImageView>(R.id.iv)
        GlideUtil.loadImage(context,entity.goods_thumb,iv)

        helper.setText(R.id.tv, entity.goods_name)
    }

    override fun onChildClick(helper: BaseViewHolder, view: View, data: BaseNode, position: Int) {
        super.onChildClick(helper, view, data, position)
        if(view.id==R.id.iv){
            val brandBean: BrandBean = data as BrandBean
            (context as Activity).startActivity<ActivityGoodList>(
                "mode" to ActivityGoodList.MODE_BRANDID,
                "brandid" to brandBean.goods_id)
        }
    }
}